package bit_exercises.Day19;

import java.util.*;

/**
 * @author zerorain
 * @date 2022/05/16 15:54
 **/
//第一题 汽水瓶
//public class Main {
//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        int n;
//        while ((n = sc.nextInt()) != 0) {
//            System.out.println(getNum(n));
//        }
//    }
//
//    private static int getNum(int num) {
//        int sum = 0;
//        while (num > 1) {
//            sum += num / 3;
//            num = num / 3 + num % 3;
//            if (num  == 2) {
//                ++sum;
//                break;
//            }
//        }
//        return sum;
//    }
//}


import java.io.*;
import java.util.*;
public class Main {
    //假设str1长度短
    public static String getMaxSubstr(String str1, String str2) {
        char[] arr1 = str1.toCharArray();
        char[] arr2 = str2.toCharArray();
        int len1 = arr1.length;
        int len2 = arr2.length;
        //最长子串的起始位置
        int start = 0;
        //最长子串的长度
        int maxLen = 0;
        //多增加一行一列，作为辅助状态
        // 状态： 以a的第i个字符结尾和以b的第j个字符结尾的最长公共子串的长度
        int[][] maxSubLen = new int[len1 + 1][len2 + 1];
        for(int i = 1; i <= len1; ++i) {
            for(int j = 1; j <= len2; ++j) {
                //如果第i个字符和第j个字符相等，则进行累加
                if(arr1[i - 1] == arr2[j - 1]) {
                    maxSubLen[i][j] = maxSubLen[i - 1][j - 1] + 1;
                    //更新
                    if(maxLen < maxSubLen[i][j]) {
                        maxLen = maxSubLen[i][j];
                        start = i - maxLen;
                    }
                }
            }

        }
        return str1.substring(start, start + maxLen);
}
public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String str1;
    String str2;
    while((str1 = reader.readLine()) != null) {
        str2 = reader.readLine();
        if(str1.length() < str2.length()) {
            System.out.println(getMaxSubstr(str1, str2));
        }
        else {
            System.out.println(getMaxSubstr(str2, str1));
        }
        }
    }
}